/**
 * 获取所有车辆的名称并且赋值
 */
function getCarName() {
    $.get("http://localhost:8001/vehicle/carTraining/carNames", function (result) {
        var carsSelected = $("#cars");
        let option = "";
        for (let i = 0; i < result.length; i++) {
            option += "<option value='" + result[i] + "'>" + result[i] + "</option>"
        }
        carsSelected.append(option);
        carsSelected.selectpicker("refresh");
        console.log(carsSelected);
    });
}

/**
 * 获取指定车辆的轨迹信息
 */
function getCarTrainInfo(carName) {
    $.get("http://localhost:8001/vehicle/carTraining/car/" + carName, function (result) {
        for (var i = 0; i < result.length; i++) {
            getPositionByLonLats(result[i].longtitude, result[i].latitude, result[i]);
        }
        setTimeout(function () {
            //绘制表格
            var currentPage = $dataTable.page();
            $dataTable.rows().remove();
            $dataTable.rows.add(result).draw().page(currentPage).draw(false);
            //绘制轨迹
            var lineArray = [];
            for (var i = 0; i < result.length; i++) {
                lineArray.push([result[i].longtitude, result[i].latitude]);
            }
            drawPolyline(lineArray);
        }, 2000);
    });
}


/**
 * 获取所有的收费站或者门架信息
 */
function getStationInfo() {
    $.get("http://localhost:8001/vehicle/stationInfo/", function (result) {
        for (var i = 0; i < result.length; i++) {
            addPositionToMap(result[i].longitude, result[i].latitude, result[i].flag);
        }
    });
}